<template>
  <div id="userLayout" :class="['user-layout-wrapper', isMobile && 'mobile']">
    <div class="container">
      <div class="user-layout-lang">
        <select-lang class="select-lang-trigger" />
      </div>
      <div class="top">
        <div class="header">
          <div class="center">
            <h1 style="display: flex; align-items: center; justify-content: center">
              <img src="/logo.png" alt="" height="40px" />
              <span class="white" style="color: #fff">比目鱼</span>
              <span class="white smaller-80" style="color: #fff" id="id-text2">- {{ info.tenantName ?? '进销存管理系统' }}</span
              >
            </h1>
          </div>
        </div>
      </div>
      <div class="user-layout-content">
        <router-view />
        <div class="footer" style="color: #478fca !important; font-size: 13px">
          服务到期时间为{{ time.timeText ?? 0 }}(剩余{{ days == ''? 0 : days }})，祝您使用愉快！
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { deviceMixin } from '@/store/device-mixin'
import SelectLang from '@/components/SelectLang'
import { getTenantUsingGET } from '@/api/api/quanxianrenzhengguanli.ts'
import { formatDate } from '@/utils/formatDate'
import { computer } from '@/utils/computer'
export default {
  name: 'UserLayout',
  components: {
    SelectLang,
  },
  data() {
    return {
      info: {},
      time: '',
      days:'',
      timer: null,
    }
  },
  mixins: [deviceMixin],
  mounted() {
    const octalRegex = /^(0o)?[0-7]+$/i
    const tenantIdStr  = window.location.host.split('.')?.[0]
    const tenantId =octalRegex.test(tenantIdStr)? tenantIdStr :1
    getTenantUsingGET({ id: tenantId})
        .then((res) => {
         if(res.code == 200){
          this.timeStart()
          this.info = res.data
          this.time = formatDate(new Date(res.data.expire))
         }
        })
        .catch((error) => {
          this.$message.error(((error.response || {}).data || {}).msg || '请求出现错误')
        })
  },
  methods: {
    timeStart() {
      // 设置定时器
      this.timer = setInterval(() => {
        this.days = computer(this.info.expire)
      }, 1200)
    },
  },
  beforeDestroy() {
    this.timer = null
    document.body.classList.remove('userLayout')
  },
}
</script>

<style lang="less" scoped>
#userLayout.user-layout-wrapper {
  height: 100%;

  &.mobile {
    .container {
      .main {
        max-width: 368px;
        width: 98%;
      }
    }
  }

  .container {
    width: 100%;
    min-height: 100%;
    background-color: #1d2024;
    // background: #f0f2f5 url(~@/assets/background.svg) no-repeat 50%;
    background-size: 100%;
    //padding: 50px 0 84px;
    position: relative;

    .user-layout-lang {
      width: 100%;
      height: 40px;
      line-height: 44px;
      text-align: right;

      .select-lang-trigger {
        cursor: pointer;
        padding: 12px;
        margin-right: 24px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 18px;
        vertical-align: middle;
      }
    }

    .user-layout-content {
      position: relative;
      width: 500px;
      left: 50%;
      border: #394557 3px solid;
      top: 50%;
      transform: translate(-50%);
      padding: 50px 0 24px;
      background: #fff;

      .top {
        text-align: center;

        .header {
          width: 100%;
          height: 44px;
          line-height: 44px;
          color: #fff;
          .center {
            text-align: center;
            width: 100%;
            h1 {
              .white {
                color: #fff;
              }
            }
          }
          .badge {
            position: absolute;
            display: inline-block;
            line-height: 1;
            vertical-align: middle;
            margin-left: -12px;
            margin-top: -10px;
            opacity: 0.8;
          }

          .logo {
            height: 44px;
            vertical-align: top;
            margin-right: 16px;
            border-style: none;
          }

          .title {
            font-size: 33px;
            color: rgba(0, 0, 0, 0.85);
            font-family: Avenir, 'Helvetica Neue', Arial, Helvetica, sans-serif;
            font-weight: 600;
            position: relative;
            top: 2px;
          }
        }
        .desc {
          font-size: 14px;
          color: rgba(0, 0, 0, 0.45);
          margin-top: 12px;
          margin-bottom: 40px;
        }
      }

      .main {
        min-width: 260px;
        width: 100%;
        padding: 0 50px;
        margin: 0 auto;
      }

      .footer {
        // position: absolute;
        width: 100%;
        bottom: 0;
        padding: 0 16px;
        margin: 48px 0 24px;
        text-align: center;

        .links {
          margin-bottom: 8px;
          font-size: 14px;
          a {
            color: rgba(0, 0, 0, 0.45);
            transition: all 0.3s;
            &:not(:last-child) {
              margin-right: 40px;
            }
          }
        }
        .copyright {
          color: rgba(0, 0, 0, 0.45);
          font-size: 14px;
        }
      }
    }

    a {
      text-decoration: none;
    }
  }
  @media screen and (max-width: 750px) {
    /* 在此处编写对应的样式 */
    .user-layout-content {
      position: relative;
      width: 300px !important;
      left: 50%;
      border: #394557 3px solid;
      top: 50%;
      transform: translate(-50%);
      padding: 50px 0 24px;
      background: #fff;
      .main {
        min-width: 260px !important;
        padding: 0 20px !important;
        width: 100% !important;
        margin: 0 auto !important;
      }
    }
  }
}
</style>
